package com.kedsoft.andaily.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.kedsoft.andaily.entity.Logs;
import com.kedsoft.andaily.service.LogsService;
import com.kedsoft.andaily.vo.PageVo;
import com.kedsoft.andaily.vo.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 * 操作日志 前端控制器
 * </p>
 *
 * @author LGP
 * @since 2019-04-26
 */
@Controller
@RequestMapping("/logs")
public class LogsController extends BaseController {

    @Autowired
    LogsService logsService;

    @RequestMapping(value = "list")
    @ResponseBody
    public PageVo<Logs> getPageList(Pagination pagination){
        EntityWrapper<Logs> entityWrapper = new EntityWrapper<>();
        if(pagination.getOrder()!=null) {
            if (pagination.getOrder().toLowerCase().equals("asc")){
                entityWrapper.orderBy(pagination.getSort(), true);
            }else{
                entityWrapper.orderBy(pagination.getSort(), false);
            }
        }
        Page<Logs> page = new Page<>(pagination.getPage()==null?1:pagination.getPage(),
                pagination.getRows()==null?20:pagination.getRows());

        logsService.selectPage(page,entityWrapper);
        PageVo<Logs> pageVo = new PageVo<>(page.getRecords(),page.getTotal());
        return pageVo;
    }
}

